package com.lxh.lxhcrm.model.pojos;

import javax.persistence.*;
import java.util.List;
import java.util.Objects;

/**
 * 商品分类
 */
@Entity
@Table(name = "pro_classily", schema = "lxh_crm")
public class ProClassily {
    private int proClassilyId;
    private String proClassilyName;
    /** 子分类 */
    private List<ProClassily> sonClassily;
    /** 父分类 */
    private ProClassily faProClassily;

    @ManyToOne()
    @JoinColumn(name = "fa_id")
    public ProClassily getFaProClassily() {
        return faProClassily;
    }

    public void setFaProClassily(ProClassily faProClassily) {
        this.faProClassily = faProClassily;
    }

    @OneToMany(mappedBy = "faProClassily",fetch = FetchType.LAZY)
    public List<ProClassily> getSonClassily() {
        return sonClassily;
    }

    public void setSonClassily(List<ProClassily> sonClassily) {
        this.sonClassily = sonClassily;
    }


    @Id
    @Column(name = "pro_classily_id", nullable = false)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public int getProClassilyId() {
        return proClassilyId;
    }

    public void setProClassilyId(int proClassilyId) {
        this.proClassilyId = proClassilyId;
    }

    @Basic
    @Column(name = "pro_classily_name", nullable = true, length = 40)
    public String getProClassilyName() {
        return proClassilyName;
    }

    public void setProClassilyName(String proClassilyName) {
        this.proClassilyName = proClassilyName;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        ProClassily that = (ProClassily) o;
        return proClassilyId == that.proClassilyId &&
                Objects.equals(proClassilyName, that.proClassilyName) &&
                Objects.equals(sonClassily, that.sonClassily) &&
                Objects.equals(faProClassily, that.faProClassily);
    }

    @Override
    public int hashCode() {
        return Objects.hash(proClassilyId, proClassilyName, sonClassily, faProClassily);
    }

    @Override
    public String toString() {
        return "ProClassily{" +
                "proClassilyId=" + proClassilyId +
                ", proClassilyName='" + proClassilyName + '\'' +
                ", sonClassily=" + sonClassily +
                ", faProClassily=" + faProClassily +
                '}';
    }
}
